# !/usr/bin/python
# _*_ coding=utf-8 _*_
# Filename : httplib2_postfile.py

import httplib2
import multipart_encode

# multipart通信用分隔符定义
BOUNDARY = '----abcd1234ABCD1234'

# multipart格式化工具 定义
multipartbody = multipart_encode.MultipartEncode(BOUNDARY)

# 追加文件
multipartbody.add_file('file1', 'py.ico', 'py.ico')
multipartbody.add_value('parame', 'hello!')

# httplib2 http实例
# httpclient = httplib2.Http('.cache')
httpclient = httplib2.Http()

# head 定义
headers={'Content-Type': 'multipart/form-data; boundary=%s' % BOUNDARY, 'Connection':'close', 'cache-control':'no-cache'}

# 请求
# resp, content = h.request('http://192.168.1.55/httplib2_postfile_res.py?itme=test01', 'GET', headers=headers)
resp, content = httpclient.request('http://192.168.1.55/httplib2_postfile_res.py', 'POST', headers=headers, body=multipartbody.get_body())

# 结果输出
print (content)